//
//  VideoViewController.m
//  PublicInfo
//
//  Created by enghou on 2018/1/18.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "VideoViewController.h"
#import "CLPlayerView.h"
@interface VideoViewController ()

@end

@implementation VideoViewController{
    CLPlayerView *player;
}

-(CLPlayerView *)configVideoWithURL:(NSURL *)url{
    CLPlayerView *playerView = [[CLPlayerView alloc] initWithFrame:CGRectMake(0, self.view.height / 2 - 100, self.view.width, 200)];
    
    //    CLPlayerView *playerView = [[CLPlayerView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    
    [self.view addSubview:playerView];
    //    //全屏是否隐藏状态栏，默认一直不隐藏
    playerView.fullStatusBarHiddenType = FullStatusBarHiddenFollowToolBar;
    //    //转子颜色
    playerView.strokeColor = [UIColor redColor];
    //    //工具条消失时间，默认10s
    playerView.toolBarDisappearTime = 8;
    //    //顶部工具条隐藏样式，默认不隐藏
    playerView.topToolBarHiddenType = TopToolBarHiddenSmall;
    //视频地址
    if (url) {
        playerView.url = url;//[NSURL URLWithString:url];
    }
    //播放
    [playerView playVideo];
    //返回按钮点击事件回调,小屏状态才会调用，全屏默认变为小屏
    [playerView backButton:^(UIButton *button) {
        NSLog(@"返回按钮被点击");
    }];
    
    [playerView endPlay:^{
        self.navigationController.hidesBarsOnTap = NO;
        self.navigationController.navigationBar.barTintColor = [UIColor defaultNavibackgroundColor];
        self.navigationController.navigationBar.hidden = NO;
        
        [self pop];
    }];
    return playerView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self defaultBackButton];
    player = [self configVideoWithURL:_url];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithWhite:0 alpha:0.5];
    self.navigationController.navigationBar.hidden = YES;
    self.navigationController.hidesBarsOnTap = YES;
    // Do any additional setup after loading the view.
}

-(void)dealloc{
    [player destroyPlayer];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
